package com.hjq.fcloud.widget

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.widget.RelativeLayout
import com.hjq.fcloud.R
import kotlinx.android.synthetic.main.layout_vertical_view.view.verticalContentTv
import kotlinx.android.synthetic.main.layout_vertical_view.view.verticalTitleTv

/**
 * 垂直item view
 */
class VerticalItemView : RelativeLayout {
    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        inflateView(attrs)
    }


    private fun inflateView(attrs: AttributeSet?) {
        inflate(context, R.layout.layout_vertical_view, this)

        val array: TypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.VerticalItemView)
        // 文本设置
        if (array.hasValue(R.styleable.VerticalItemView_titleText)) {
            setTitle(array.getString(R.styleable.VerticalItemView_titleText))
        }
        if (array.hasValue(R.styleable.VerticalItemView_contentText)) {
            setContent(array.getString(R.styleable.VerticalItemView_contentText))
        }
        array.recycle()
    }

    fun setTitle(title: CharSequence?) {
        verticalTitleTv.setText(title)
    }

    fun setContent(title: CharSequence?) {
        verticalContentTv.setText(title)
    }

}